/*
by roc,2009/12/23,全局脚本
by roc,2010/01/28,封装/修改全局取值方法,修改取客户资料位置
*/

//===========================全局变量定义开始========================================
//客户ID
var GlobalCustomerID;
//客户类型
var GlobalUserType;
//客户名称
var GlobalUserName;
//客户来电号码
var GlobalUserPhone;
//客户的默认联系人
var GlobalLinker;
//客户编号
var GlobalCustomerNo;
//获取当前客户的支付方式
var GlobalPayType;
//获取当前客户的配送方式
var GlobalSendType;
//来电弹出客户区域frame名
var GlobalCallCenterCustomerArea = "frmCallInCusInfo";

//登录UID
var GlobaUid;
//配送部门ID
var GlobalSendDepId;
//配送部门名称
var GlobalSendDepName;
//全局调试开关
var GlobalDebugFlag = false;
var GlobalDebugFlagReturn = false;

//===========================全局变量定义结束========================================

//取来电客户区域frame对象
function GetCallCenterFrameObj()
{
    var framename = GlobalCallCenterCustomerArea;
    var obj;
    obj = window.parent.document.getElementById(framename);
    return obj;
}


//根据para名称获取客户相关信息
function GetGlobalCustomerRelationInfo(para,paratype,valuetype)
{
    var ret;
    try
    {
        var framename = GlobalCallCenterCustomerArea;
        var obj;
        obj = window.parent.document.getElementById(framename).contentWindow.document.getElementById(para);
        if(obj == null)
            obj = window.parent.document.getElementById(framename).document.getElementById(para);

        if(paratype == "option")
        {
            if(valuetype == "text")
            {
                ret = obj.options[obj.selectedIndex].innerText;
            }
            else
            {
                ret = obj.options[obj.selectedIndex].value;
            }
        }
        else
        {
            ret = obj.value;
        }
    }
    catch(ex)
    {
        ret = '';
    }
    if(GlobalDebugFlag)
    {
        alert("debug:\n" + "   Para:" + para + "   /ParaType:" + paratype + "   /ValueType:" + valuetype + "   /ReturnValue:" + ret);
    }
    return ret;
}

//获取选择的全局客户ID
function GetGlobalCustomerID()
{
    try
    {
        GlobalCustomerID = GetGlobalCustomerRelationInfo("h_cusid","","");
        //top.window.frames['phoneOperation'].document.getElementById("h_cusid").value;
    }
    catch(ex)
    {
        GlobalCustomerID = '';
    }
}

//获取登录UID  GlobaUid
function GetGlobalUID() {
    try {
        GlobaUid = GetGlobalCustomerRelationInfo("h_opid", "", "");
        //top.window.frames['phoneOperation'].document.getElementById("h_cusid").value;
    }
    catch (ex) {
        GlobaUid = '';
    }
}

//获取选择的全局用户类型
function GetGlobalUserType()
{
    //Platform
    try
    {
        GlobalUserType = GetGlobalCustomerRelationInfo("GlobalUserType","","");
        //top.window.frames['phoneOperation'].document.getElementById("GlobalUserType").value;
    }
    catch(ex)
    {
        GlobalUserType = '';
    }
}

//获取选择的全局用户名称
function GetGlobalUserName() {
    try {
        GlobalUserName = GetGlobalCustomerRelationInfo("txbCusName","","");
        //top.window.frames['phoneOperation'].document.getElementById("txbCusName").value;
    }
    catch (ex) {
        GlobalUserName = "";
    }
}
//获取选择的全局用户来电号码
function GetGlobalPhone() {
    try {
        GlobalUserPhone = GetGlobalCustomerRelationInfo("txbPhoneNO","","");
        //top.window.frames['phoneOperation'].document.getElementById("txbPhoneNO").value;
    }
    catch (ex) {
        GlobalUserPhone = "";
    }
    return GlobalUserPhone;
}
//获取默认联系人
function GetGlobalLinker() {
    try {
        GlobalLinker = GetGlobalCustomerRelationInfo("txbLinkMan","","");
        //top.window.frames['phoneOperation'].document.getElementById("txbLinkMan").value;
    }
    catch (ex) {
        GlobalLinker = "";
    }
}
//获得客户编号
function GetGlobalCustomerNo()
{
    GetGlobalCusNO();
}
function GetGlobalCusNO() {
    try {
        GlobalCustomerNo = GetGlobalCustomerRelationInfo("txbOrderCusNO","","");
        //top.window.frames['phoneOperation'].document.getElementById("txbOrderCusNO").value;
    }
    catch (ex) {
        GlobalCustomerNo = "";
    }
}
//获取选择的支付方式
function GetGlobalPayType() {
    try {
        GlobalPayType = GetGlobalCustomerRelationInfo("drpPayType", "option", "");
    }
    catch (ex) {
        GlobalPayType = "ZH";
    }
    return GlobalPayType;
}
//配送部门ID
function GetGlobalSendDepID() {
    try {
        GlobalSendDepId = GetGlobalCustomerRelationInfo("drpDepName", "option", "");
    }
    catch (ex) {
        GlobalSendDepId = "";
    }
    return GlobalSendDepId;
}
//获取配送部门名称
function GetGlobalSendDepName() {
    try {
        GlobalSendDepName = GetGlobalCustomerRelationInfo("drpDepName", "option", "text");
    }
    catch (ex) {
        GlobalSendDepName = "";
    }
    return GlobalSendDepName;
}
//获取配送日期
var GlobalSendDate;
function GetGlobalSendDate() {
    try {
        GlobalSendDate = GetGlobalCustomerRelationInfo("txtSendDate", "", "");
    }
    catch (ex) {
        GlobalSendDate = "";

    }
    return GlobalSendDate;
}
//获取配送时间
var GlobalSendTime;
function GetGlobalSendTime() {
    try {
        GlobalSendTime = GetGlobalCustomerRelationInfo("txtSendTime", "", "");
    }
    catch (ex) { GlobalSendTime = ""; }
    return GlobalSendTime;
}
//获取配送方式
var GlobalSendType;
function GetGlobalSendType() {
    try {
        GlobalSendType = GetGlobalCustomerRelationInfo("drpSendType", "", "");
    }
    catch (ex) {
        GlobalSendType = "";
    }
    return GlobalSendType;
}
//是否打印行程单
var GlobalIsPrintSerial;
function GetGlobalIsPrintSerial() {
    GlobalIsPrintSerial = "N";
    try {
        var tmp = window.parent.document.getElementById(framename).document.getElementById("chkPrint");
        if (tmp.checked == true) {
            GlobalIsPrintSerial = "Y";
        }
    }
    catch (ex) {
        GlobalIsPrintSerial = "N";
    }
    return GlobalIsPrintSerial;
}
//配送地址
var GlobalSendAddress;
function GetGolbalSendAddress() {
    GlobalSendAddress = "";
    try {
            GlobalSendAddress = GetGlobalCustomerRelationInfo("txbDeliveryAddress", "", "");
    }
    catch (ex) {

    }
    return GlobalSendAddress;
}
//切换到黑屏页面
function ChangeToPowerTermScreen()
{
    //document.getElementById("switchPoint").value=3;
    //GetGlobalCustomerID();
	var Obj = window.parent.document.getElementById("mainframeB");
    if(Obj.cols.indexOf("185")>-1)
        Obj.cols = "0,*,185";
    else
	    Obj.cols = "0,*,0";
}

//执行黑屏页的Command方法
function ExecutePowerTermScreenFunction(functionName,paras)
{
        var o = window.parent.document.getElementById("PowerTermShow").contentWindow;
        eval(functionName + '(' + paras + ')');
        //o.PTermFromOrderPage(officeNo,Pnr);
}

//切换到工作区页面
function ChangeToWorkScreen()
{
    //document.getElementById("switchPoint").value=3;
    //GetGlobalCustomerID();
    //window.top.document.getElementById("mainframeB").cols="604,0";
    if(GlobalDebugFlag)
    {
        alert('start ChangeToWorkScreen...');
    }
    var Obj = window.parent.document.getElementById("mainframeB");
    if(Obj.cols.indexOf("185")>-1)
        Obj.cols = "*,0,185";
    else
	    Obj.cols = "*,0,0";
}

function SwitchPowerTermAndWorkScreen()
{
    var leftcol = window.parent.document.getElementById("mainframeB").cols;
    if(leftcol.substring(0,1) == '0')
        ChangeToWorkScreen();
    else
        ChangeToPowerTermScreen();
}

//打开白屏预订页面
function ChangeToWhiteScreen()
{
    ShowPhoneCustomerScreen();
    ChangeToWorkScreen();
    var win = window.parent.frames["mainShow"];
    var url = '/FlightReserve/PopFlightOrder/FlightSearch.aspx';
    OpenUrlInWorkScreen(win,url,'');
}

//===========================菜单树区域操作功能定义开始========================================
//隐藏菜单树
function HiddenMenuTree()
{
    var middleObj = window.parent.document.getElementById("frame");
    middleObj.cols = "0,12,*";

      var obj = window.parent.document.getElementById("frmSplitor").contentWindow.document.getElementById("switchPoint");
    obj.innerText=4;
}
//展开菜单树
function ShowMenuTree()
{
    var middleObj = window.parent.document.getElementById("frame");
    middleObj.cols = "170,12,*";
        var obj = window.parent.document.getElementById("frmSplitor").contentWindow.document.getElementById("switchPoint");
    obj.innerText=3;
}
function SwitchMenuTree()
{
    var obj = window.parent.document.getElementById("frame");
    if(obj.cols.substring(0,2) == "0,")
        ShowMenuTree();
    else
        HiddenMenuTree();
}

//顶部菜单区域操作功能定义
//隐藏顶部菜单
function HiddenTopMenu()
{
    var middleObj = window.parent.document.getElementById("frameWork");
    middleObj.rows = "0,*,18";
}
//展开顶部菜单
function ShowTopMenu()
{
    var middleObj = window.parent.document.getElementById("frameWork");
    middleObj.rows = "87,*,18";
}
function SwitchTopMenu()
{
    var obj = window.parent.document.getElementById("frameWork");
    if(obj.rows.substring(0,2) == "0,")
        ShowTopMenu();
    else
        HiddenTopMenu();
}
//===========================菜单树区域操作功能定义结束========================================


//===========================来电客户区域操作功能定义开始========================================
//打开来电客户显示区域
function ShowPhoneCustomerScreen()
{
    //window.top.document.getElementById("mainFrame").rows="28,140,*";
    HiddenMenuTree();
    var workingObj = window.parent.document.getElementById("mainframeB");
    if(workingObj.cols.substring(0,2) == "*,")
        workingObj.cols = "*,0,185";
    else
        workingObj.cols = "0,*,185";
}

//隐藏来电客户显示区域
function HiddenPhoneCustomerScreen()
{
    ShowMenuTree();
    var workingObj = window.parent.document.getElementById("mainframeB");
    if(workingObj.cols.substring(0,2) == "*,")
        workingObj.cols = "*,0,0";
    else
        workingObj.cols = "0,*,0";
    /*
    GetGlobalCustomerID();
    if(GlobalCustomerID != '')
    {
        window.top.document.getElementById("mainFrame").rows="28,30,*";
    }
    else
    {
        window.top.document.getElementById("mainFrame").rows="28,0,*";
    }
    */
}
//切换来电客户显示区域
function SwitchPhoneCustomerScreen()
{
    var workingObj = window.parent.document.getElementById("mainframeB");
    var col = workingObj.cols;
    //alert(col);
    if(col.indexOf("185") > -1)
        HiddenPhoneCustomerScreen();
    else
        ShowPhoneCustomerScreen();
    /*
    var toprows = window.top.document.getElementById("mainFrame").rows;
    if(toprows.substring(0,5) == '28,14')
        HiddenPhoneCustomerScreen();
    else
        ShowPhoneCustomerScreen();
    */
}
//===========================来电客户区域操作功能定义结束========================================


//===========================客户查询区域操作功能定义开始========================================
//带一个参数查询
function ChangeToCustomerSearchByPara(ParaValue,ParaName)
{
    //alert("Value:" + ParaValue + "/Name:" + ParaName);
    if(ParaName == "CustomerName")
    {
        ChangeToCustomerSearch("",ParaValue,"","","");
    }
    else if(ParaName == "CardNo")
    {
        ChangeToCustomerSearch("","","",ParaValue,"");
    }
    else
    {
        ChangeToCustomerSearch();
    }
}

function ChangeToCustomerSearch(PhoneNumber,CustomerName,CustomerJP,CardNo,CustomerNo)
{
    //alert(PhoneNumber + "/" + CustomerName + "/" + CustomerJP + "/" + CardNo + "/" + CustomerNo);
    //return;
    var ext;
    var para;
    if (CustomerName != "") {
        ext = CustomerName;
        para = 'Ext=' + ext;
    }
    if (CardNo != "") {
        ext = CardNo;
        para = 'CardNo=' + ext;
    }
    ChangeToWorkScreen();
    var win = window.parent.frames["mainShow"];
    var url = '/CustomerManage/phoneOperation/CusList.aspx';



    OpenUrlInWorkScreen(win,url,para);
}


//===========================客户查询区域操作功能定义结束========================================

//在工作区打开指定参数的URL
function OpenUrlInWorkScreen(win,url,para)
{
    win.location = url + '?rand=' + (new Date()).getTime().toString() + '&' + para;
}

//在工作区打开指定参数的URL
function OpenUrlInNewWindow(win,url,para)
{
    var cururl = url + '?rand=' + (new Date()).getTime().toString() + '&' + para;
    window.open(cururl,win,'top=0,left=0,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no');
    //height=100,width=400,
}

//============================通用功能定义======================================================
//判断是否按下回车键
function CheckEnterPress()
{
    if(event.keyCode == 13)
    {
        event.returnValue=false;
        event.cancel = true;
        return true;
    }
    else
    {
        return false;
    }
}

//快捷键定义
document.onkeydown = function()
{
    if(window.event.ctrlKey&&window.event.keyCode==192)         //ctrl+`,黑屏白屏相互切换
    {
        SwitchPowerTermAndWorkScreen();
    }
    else if(window.event.ctrlKey&&((window.event.keyCode==49)||(window.event.keyCode==97)))         //ctrl+1,来电客户信息屏显示/隐藏切换
    {
        SwitchPhoneCustomerScreen();
    }
    else if(window.event.ctrlKey&&((window.event.keyCode==51)||(window.event.keyCode==99)))         //ctrl+3,切换到最大屏显示
    {
        HiddenPhoneCustomerScreen();
        HiddenMenuTree();
        HiddenTopMenu();
    }
}